package com.dwxt.sport.business.controller;

import com.dwxt.common.base.BaseResult;
import com.dwxt.sport.business.entity.Street;
import com.dwxt.sport.business.service.StreetService;
import com.dwxt.sport.business.vo.street.SelectStreetVo;
import com.dwxt.sport.business.vo.street.InsertStreetVo;
import com.dwxt.sport.business.vo.street.UpdateStreetVo;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 街道 Controller
 *
 * @author Kuang.JiaZhuo
 * @date 2020-07-24 16:30
 */
@RestController
@RequestMapping("/street")
@Api(tags={"街道业务接口"})
public class StreetController {

    @Resource
    StreetService streetService;


//    @ApiOperation(value = "新增街道", notes = "新增街道", response = Integer.class)
//    @PostMapping("/back/insertStreet")
//    public BaseResult insertStreet(@RequestBody Street street){
//        int result = this.streetService.insertStreet(street);
//        return BaseResult.ok(result);
//    }

    @ApiOperation(value = "新增街道", notes = "新增街道", response = Integer.class)
    @PostMapping("/back/insertStreet")
    public BaseResult insertStreet(InsertStreetVo insertStreetVo){
        int result = this.streetService.createStreet(insertStreetVo);
        return BaseResult.ok(result);
    }

//    @ApiOperation(value = "更新街道", notes = "更新街道", response = Integer.class)
//    @PostMapping("/back/updateStreet")
//    public BaseResult updateStreet(Street street){
//        int result = this.streetService.updateStreet(street);
//        return BaseResult.ok(result);
//    }

    @ApiOperation(value = "更新街道", notes = "更新街道", response = Integer.class)
    @PostMapping("/back/updateStreet")
    public BaseResult updateStreet(UpdateStreetVo updateStreetVo){
        int result = this.streetService.modifyStreet(updateStreetVo);
        return BaseResult.ok(result);
    }

    @ApiOperation(value = "获取街道列表", notes = "获取街道列表(带分页)", response = Street.class)
    @PostMapping("/back/getStreetListByPage")
    public BaseResult getStreetListByPage(SelectStreetVo selectStreetVo){
        PageInfo<Street> pageInfo = this.streetService.getStreetListByPage(selectStreetVo);
        return BaseResult.ok(pageInfo);
    }

    @ApiOperation(value = "删除街道", notes = "传入ids批量删除街道", response= Integer.class)
    @PostMapping(value = "/back/deleteStreetByIds")
    public BaseResult deleteStreetByIds(@ApiParam(value = "要删除的id字符串,以英文逗号隔开", required = true) @RequestParam String ids){
        int result = this.streetService.deleteStreetByIds(ids);
        return BaseResult.ok(result);
    }
}
